package com.yanqu.road.server.manger.union.listener;

import com.yanqu.road.entity.enums.eUnionSyncType;
import com.yanqu.road.entity.union.cross.CrossUnionInfo;
import com.yanqu.road.entity.union.cross.CrossUnionMember;
import com.yanqu.road.server.GameServer;
import com.yanqu.road.server.manger.ICrossUnionSyncListener;
import com.yanqu.road.server.manger.activity.seacraft.SeacraftSouthSeaMgr;

import java.util.List;

/**
 * @Description 南海丝路
 * @Author cwq
 * @Data 2022/4/26 11:14
 */
public class SeacraftSouthSeaListener implements ICrossUnionSyncListener {
    @Override
    public void notifySync(int syncType, long playerId, CrossUnionInfo unionInfo, List<CrossUnionMember> memberList) {
        if (syncType == eUnionSyncType.Normal.getValue()) {
            if(unionInfo != null && unionInfo.getServerId() == GameServer.getInstance().getServerId()){
                SeacraftSouthSeaMgr.synUnionInfo(1, unionInfo.getUnionUid(), 0, unionInfo);
            }
        } else if (syncType == eUnionSyncType.JoinUnion.getValue() || syncType == eUnionSyncType.CreateUnion.getValue()) {
            // 加入联盟
            for (CrossUnionMember member : memberList) {
                if (member.getServerId() != GameServer.getInstance().getServerId()) {
                    continue;
                }
                SeacraftSouthSeaMgr.synUnionInfo(2, unionInfo.getUnionUid(), member.getUserId(), null);
            }
        } else if (syncType == eUnionSyncType.BeKick.getValue() ||syncType == eUnionSyncType.QuitUnion.getValue() || syncType == eUnionSyncType.DeleteUnion.getValue()) {
            // 退出联盟
            for (CrossUnionMember member : memberList) {
                if (member.getServerId() != GameServer.getInstance().getServerId()) {
                    continue;
                }
                SeacraftSouthSeaMgr.synUnionInfo(3, unionInfo.getUnionUid(), member.getUserId(), null);
            }
        }
    }
}
